﻿using System.Threading;
using System.Windows;
using System.Text;
using System;
using System.Windows.Threading;
using POEApi.Infrastructure;

namespace PoESsb
{
    public partial class App : Application
    {
        public App()
        {
            Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
        }

        void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            Logger.Log("Versão: " + ApplicationState.Version);
            Logger.Log(getEnvironementDetails());
            Logger.Log(e.Exception.ToString());
            MessageBox.Show("Erro não tratado - Oops! É a vida.");
        }

        private string getEnvironementDetails()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                builder.AppendLine("CurrentCulture: " + Thread.CurrentThread.CurrentCulture.ToString());
                builder.AppendLine("CurrentUICulture: " + Thread.CurrentThread.CurrentUICulture.ToString());
            }
            catch (Exception ex)
            {
                builder.AppendLine(ex.ToString());
            }

            return builder.ToString();
        }
    }
}